package com.virgo.demo.support.task;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.virgo.common.utils.ITimeUtils;
import com.virgo.demo.support.domain.OperationLogDo;
import com.virgo.demo.support.mapper.OperationLogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class OperationLogTask {

	@Autowired
	private OperationLogMapper operationLogMapper;

	/**
	 * 清除一年前的操作日志
	 */
	@Scheduled(cron = "0 32 1 * * ?")
	public void clear() {
		long queryTime = ITimeUtils.gmTime();
		queryTime -= 365L*86400L;
		LambdaQueryWrapper<OperationLogDo> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.le(OperationLogDo::getCreatedAt,queryTime);
		operationLogMapper.delete(queryWrapper);
	}
}